<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>gcal test</title>


<script type="text/javascript" src="jquery.js"></script>
<!--
<script src="http://www.google.com/jsapi?key=ABQIAAAANU8OAqbJPAHXV4SpKuTEvhQx6TWrfC8bNfnC-vtzzHJYkwhD6xSt50-Z_44EojojRLDiBj3kn932Rw" type="text/javascript"></script>
-->
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("gdata", "2.x", {packages: ["calendar"]});
google.setOnLoadCallback(_doCalendar);


function _doCalendar() {
  var feedUrl = "https://www.google.com/calendar/feeds/u6g675oejpdha4pncv50rmi8tc%40group.calendar.google.com/public/basic?q=wotd";
  var calendarService = new google.gdata.calendar.CalendarService('LiquidChicken-jsWotdStandAlone-1.0');
  var query = new google.gdata.calendar.CalendarEventQuery(feedUrl);
  var maxResults = 10;
  var displayCount = 1;

  query.setOrderBy('starttime');
  query.setSortOrder('ascending');
  query.setFutureEvents(true);
  query.setSingleEvents(true);
  query.setMaxResults(maxResults);

  var callback = function (result) {
    var entries = result.feed.getEntries();
    $('#gcal').html('');
                if (options.displayCount) {
                    $('#gcal').html(entries.length + ' upcoming events');
                }
                $('#gcal').append('<ul id="eventlist"></ul>');

                for (var i = 0; i < entries.length; i++) {
                    var eventEntry = entries[i];
                    var eventTitle = eventEntry.getTitle().getText();
                    var startDateTime = null;
                    var eventDate = null;
                    var eventWhere = null;
                    var eventContent = eventEntry.getContent().getText();

                    var times = eventEntry.getTimes();
                    if (times.length > 0) {
                        startDateTime = times[0].getStartTime();
                        eventDate = startDateTime.getDate();
                    }

                    var d_names = new Array("Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat");
                    var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec");

                    var a_p = "";
                    var d = eventDate;
                    var curr_hour = d.getHours();
                    if (curr_hour < 12) {
                        a_p = "am";
                    }
                    else {
                        a_p = "pm";
                    }
                    if (curr_hour == 0) {
                        curr_hour = 12;
                    }
                    if (curr_hour > 12) {
                        curr_hour = curr_hour - 12;
                    }

                    var curr_min = d.getMinutes();
                    curr_min = curr_min + "";

                    if (curr_min.length == 1) {
                        curr_min = "0" + curr_min;
                    }

                    var time = curr_hour + ':' + curr_min + a_p;
                    var day = eventDate.getDay();
                    var month = eventDate.getMonth();
                    var date = eventDate.getDate();
                    var dayname = d_names[day];
                    var monthname = m_names[month];
                    var location = eventEntry.getLocations();
                    var eventWhere = location[0].getValueString();

                    var eventhtml = '<div id="eventtitle">' + eventTitle + '</div>  When: ' + dayname + ' ' + monthname + ' ' + date + ', ' + time + '<br>Where: ' + eventWhere + '<br>' + eventContent;
                    $('#eventlist').append('<li>' + eventhtml + '</li>');
                }
            };

            // Error handler to be invoked when getEventsFeed() produces an error
            var handleError = function (error) {
                $('#gcal').html('<pre>' + error + '</pre>');
            };

            // Submit the request using the calendar service object
            calendarService.getEventsFeed(query, callback, handleError);
//  calendarService.getEventsFeed(feedUrl, handleMyFeed, handleError);
}

function handleMyFeed(result) {
//  alert("This feed's title is: " + result.feed.getTitle().getText());
  // Obtain the array of CalendarEventEntry
  var entries = result.feed.entry;    
  
  // Print the total number of events
//  PRINT('Total of ' + entries.length + ' event(s)');
//  var totalEvents = '<p>Total of ' + entries.length + ' event(s)</p>';
//  $('#wotdHead').append(totalEvents);

  $('#wotdList').append("<table>\n");
  $('#wotdList').append("<tr><th>WOTD</th><th>DATE</th></tr>\n");
  for (var i = 0; i < entries.length; i++ ) {
    var eventEntry = entries[i];
    var eventTitle = eventEntry.getTitle().getText();
    var eventSum = eventEntry.getSummary();
    var eventSumText = eventEntry.getSummary().getText();
    var eventTimes = eventEntry.getTimes();

    var extProps = eventEntry.content;
//    PRINT('Event title = ' + eventTitle);
    $('#wotdList').append('<tr><td>' + eventTitle + "</td><td>" + eventSumText + "</td></tr>\n");
  } 
  $('#wotdList').append("</table>\n");
}

function handleError(e) {
  alert("There was an error!");
  alert(e.cause ? e.cause.statusText : e.message);
}

function logMeIn() {
  scope = "https://www.google.com/calendar/feeds/";
  var token = google.accounts.user.login(scope);
}

function main() {
    // Create the calendar service object
    calendarService = new google.gdata.calendar.CalendarService(calService);
    // Submit the request using the calendar service object
    calendarService.getEventsFeed(feedUri, callback, handleError);
}


</script>
</head>
<body>
<img src="/~ksetzer/images/blank.gif" style="position:absolute; top: -1000px;"/>

<div id="wotdList"/>

<hr>
<div id="gcal"/"

</body>
</html>


